package tc.jv.task6;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;

import tc.jv.task4.Vector;

public class Vectors extends tc.jv.task5.Vectors
{

	public static Vector inputVector(InputStream in)
	{
		DataInputStream dis = new DataInputStream(in);
		try
		{
			int size = dis.readInt();
			Vector v = tc.jv.task7.Vectors.createInstance();//new LinkedListVector();
			while (size-- > 0)
				v.add(dis.readDouble());
			return v;
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	public static void outputVector(Vector v, OutputStream out)
	{
		DataOutputStream dos = new DataOutputStream(out);
		try
		{
			int size = v.size();
			dos.writeInt(size);
			for (int i = 0; i < size; i++)
				dos.writeDouble(v.get(i));
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static Vector readVector(Reader in)
	{
		StreamTokenizer st = new StreamTokenizer(in);
		try
		{
			st.nextToken();
			int size = (int) st.nval;
			Vector v = tc.jv.task7.Vectors.createInstance();//new LinkedListVector();
			while (size-- > 0)
			{	
				st.nextToken();
				v.add(st.nval);
			}
			return v;
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	public static void writeVector(Vector v, Writer out)
	{
		try
		{
			out.write(Integer.toString(v.size()) + " ");
			for (int i = 0; i < v.size(); i++)
				out.write(v.get(i) + " ");
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
}
